/**
 * 
 */
package com.effectivsocial.security;


import javax.inject.Named;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;

import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

import com.effectivsocial.domain.Company;
import com.effectivsocial.domain.User;


/**
 * @author Dhrubo
 *
 */
@Named
@Slf4j
public class SimpleAuthenticationSuccessHandler extends
		SavedRequestAwareAuthenticationSuccessHandler {
	
	private String normalLanding = "/dashboard.jsf";
	private String companySetupLanding = "/setupcompany.jsf";

	@Override
	protected String determineTargetUrl(HttpServletRequest request,
			HttpServletResponse response) {
		String targetUrl = normalLanding;
		User user = SecurityUtil.getUserDetails();
		
		log.info("## Logged in user - {}", user);
		
		Company company = user.getCompany();
		
		if(company == null) {
			targetUrl = companySetupLanding;
		}
		
		return targetUrl;
	}

	

}
